package cn.vote.filter;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Filter implementation class Filter
 */
public class Filter implements javax.servlet.Filter {


	public void destroy() {
	
	}


	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		/**
		 * 获取session，对session进行判断
		 */
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse resp = (HttpServletResponse) response;
		Object sessionUser = req.getSession().getAttribute("sessionUser");
		if (sessionUser == null) {
			req.setAttribute("error3", "您还没登录，请不要瞎逛！");
			req.getRequestDispatcher("/jsps/voter.jsp").forward(req, resp);
		}else {
			chain.doFilter(request, response);
		}
	
	}

	public void init(FilterConfig fConfig) throws ServletException {
	
	}

}
